class Solution {
public:
    int getNumberSameAsIndex(vector<int>& nums) {
        if(nums.empty())
            return 0;
        int left=0,right=nums.size();
        while(left<=right){
            int mid=(left+right)>>1;
            if(mid==nums[mid])
                return mid;
            else if(nums[mid]>mid)
                right=mid-1;
            else
                left=left+1;
        }
        return -1;
    }
};